package com.xy.biz.mc.configuration;

import com.xy.biz.mc.connection.websocket.WebSocketConnection;
import com.xy.biz.mc.service.ConnectionService;
import com.xy.tool.jwt.TokenParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

@Configuration
@AutoConfigureAfter(JwtConfiguration.class)
@EnableWebSocket
public class WebSocketConfiguration implements WebSocketConfigurer {

    @Autowired
    private ConnectionService connectionService;
    @Autowired
    private TokenParser tokenParser;

    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

    @Autowired
    public void setConnectionService() {
        WebSocketConnection.setConnectionService(connectionService);
        WebSocketConnection.setTokenParser(tokenParser);
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {

    }

}
